package ${q.pkg};

<#list q.imports as imps>
import ${imps};
</#list>

/**
 *	Query (${q.e.tableName})
 *  ${q.e.tableDesc!""}
 *
 *	@author ${q.e.author!""} (${q.e.authorEnglish!""})
 *	@date ${q.e.createTime}
 */
public class ${q.className} extends ${q.e.className} implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

<#list q.fields as field>
    /**
     *  ${field.desc!""}
     */
    protected ${field.type} ${field.name};
    protected List<${field.type}> ${field.name}In;
    <#if field.like>
    protected ${field.type} ${field.name}XLike;
    protected ${field.type} ${field.name}XLeft;
    protected ${field.type} ${field.name}XRight;
    </#if>
    <#if field.compare>
    protected ${field.type} ${field.name}Gt;
    protected ${field.type} ${field.name}Gte;
    protected ${field.type} ${field.name}Lt;
    protected ${field.type} ${field.name}Lte;
    </#if>
</#list>


    public static ${q.className} build() {return new ${q.className}();}


<#list q.fields as field>
    public ${field.type} ${field.get}() {return ${field.name};}
    public void ${field.set}(${field.type} ${field.name}) { this.${field.name} = ${field.name}; }
    public ${q.className} ${field.name}(${field.type} ${field.name}) { this.${field.name} = ${field.name}; return this; }

    public List<${field.type}> ${field.get}In() {return ${field.name}In;}
    public void ${field.set}In(List<${field.type}> ${field.name}In) { this.${field.name}In = ${field.name}In; }
    public ${q.className} ${field.name}In(List<${field.type}> ${field.name}In) { this.${field.name}In = ${field.name}In; return this; }
    public ${q.className} ${field.name}Append(${field.type} ${field.name}) { if (${field.name}In == null) { ${field.name}In = new ArrayList<>(); } ${field.name}In.add(${field.name}); return this; }

    <#if field.like>
    public ${field.type} ${field.get}XLike() {return ${field.name}XLike;}
    public void ${field.set}XLike(${field.type} ${field.name}XLike) { this.${field.name}XLike = ${field.name}XLike; }
    public ${q.className} ${field.name}XLike(${field.type} ${field.name}XLike) { this.${field.name}XLike = ${field.name}XLike; return this; }

    public ${field.type} ${field.get}XLeft() {return ${field.name}XLeft;}
    public void ${field.set}XLeft(${field.type} ${field.name}XLeft) { this.${field.name}XLeft = ${field.name}XLeft; }
    public ${q.className} ${field.name}XLeft(${field.type} ${field.name}XLeft) { this.${field.name}XLeft = ${field.name}XLeft; return this; }

    public ${field.type} ${field.get}XRight() {return ${field.name}XRight;}
    public void ${field.set}XRight(${field.type} ${field.name}XRight) { this.${field.name}XRight = ${field.name}XRight; }
    public ${q.className} ${field.name}XRight(${field.type} ${field.name}XRight) { this.${field.name}XRight = ${field.name}XRight; return this; }
    </#if>
    <#if field.compare>
    public ${field.type} ${field.get}Gt() {return ${field.name}Gt;}
    public void ${field.set}Gt(${field.type} ${field.name}Gt) { this.${field.name}Gt = ${field.name}Gt; }
    public ${q.className} ${field.name}Gt(${field.type} ${field.name}Gt) { this.${field.name}Gt = ${field.name}Gt; return this; }

    public ${field.type} ${field.get}Gte() {return ${field.name}Gte;}
    public void ${field.set}Gte(${field.type} ${field.name}Gte) { this.${field.name}Gte = ${field.name}Gte; }
    public ${q.className} ${field.name}Gte(${field.type} ${field.name}Gte) { this.${field.name}Gte = ${field.name}Gte; return this; }

    public ${field.type} ${field.get}Lt() {return ${field.name}Lt;}
    public void ${field.set}Lt(${field.type} ${field.name}Lt) { this.${field.name}Lt = ${field.name}Lt; }
    public ${q.className} ${field.name}Lt(${field.type} ${field.name}Lt) { this.${field.name}Lt = ${field.name}Lt; return this; }

    public ${field.type} ${field.get}Lte() {return ${field.name}Lte;}
    public void ${field.set}Lte(${field.type} ${field.name}Lte) { this.${field.name}Lte = ${field.name}Lte; }
    public ${q.className} ${field.name}Lte(${field.type} ${field.name}Lte) { this.${field.name}Lte = ${field.name}Lte; return this; }
    </#if>


</#list>

    /**
     *  是否为空
     *  <p> 仅仅是每个字段的为空检测。若存在特殊空判，需要自行实现
     */
    public boolean isEmpty() {
    <#list q.fields as field>
        if (${field.name} != null) {return false;}
        if (${field.name}In != null && !${field.name}In.isEmpty()) {return false;}
        <#if field.like>
        if (${field.name}XLike != null && ${field.name}XLike.isEmpty()) {return false;}
        if (${field.name}XLeft != null && ${field.name}XLeft.isEmpty()) {return false;}
        if (${field.name}XRight != null && ${field.name}XRight.isEmpty()) {return false;}
        </#if>
        <#if field.compare>
        if (${field.name}Gt != null ) {return false;}
        if (${field.name}Gte != null ) {return false;}
        if (${field.name}Lt != null ) {return false;}
        if (${field.name}Lte != null ) {return false;}
        </#if>
    </#list>
        return true;
    }
    /**
     *  copy（注：这是浅拷贝）
     */
    public ${q.className} copy() {
        ${q.className} copy = new ${q.className}();
    <#list q.fields as field>
        copy.${field.name} = ${field.name};
        copy.${field.name}In = ${field.name}In;
        <#if field.like>
        copy.${field.name}XLike = ${field.name}XLike;
        copy.${field.name}XLeft = ${field.name}XLeft;
        copy.${field.name}XRight = ${field.name}XRight;
        </#if>
        <#if field.compare>
        copy.${field.name}Gt = ${field.name}Gt;
        copy.${field.name}Gte = ${field.name}Gt;
        copy.${field.name}Lt = ${field.name}Lt;
        copy.${field.name}Lte = ${field.name}Lte;
        </#if>
    </#list>
        return copy;
    }
}
